/**
 * author: XGP
 * date: 2018/07/25
 * des: 人员招聘-招聘规划
 *
 */


import {
  getOrgdetail,
  findSalaryTwo,
  getPositionApi
} from './api.js'

/**
 * 列表的set
 */
export const setting = [{
  field: 'reqId',
  title: '编号',
  type: 'text'

},
{
  field: 'reqName',
  title: '需求名称',
  type: 'text'
},
{
  field: 'orgName',
  title: '部门',
  type: 'text'
},
{
  field: 'position',
  title: '招聘岗位',
  type: 'text',
  isParams: true, // 默认为false，当isParams 为true 时，下拉数据为参数类型，
  paramsId: 'POST',
  searchable: true
},
{
  field: 'educationRequire',
  title: '学历要求',
  type: 'text',
  isParams: true, // 默认为false，当isParams 为true 时，下拉数据为参数类型，
  paramsId: 'EDUCATION',
},
{
  field: 'recruitsNumbers',
  title: '招聘人数',
  type: 'text'
},
{
  field: 'entryNumbers',
  title: '已入职人数',
  type: 'text'
},
{
  field: 'recruitProgress', // 自定义
  title: '招聘进度',
  type: 'text'
},
{
  field: 'responsiblePerson',
  title: '负责人',
  type: 'user-tree',
  isHiden: true
},
{
  field: 'startDate',
  title: '启动日期',
  type: 'date'
},
{
  field: 'statusName', // 自定义
  title: '状态',
  type: 'text'
}
]
/**
 * 详情的set
 */
export const detailSetting = [{
  field: 'reqId',
  title: '编号',
  type: 'text',
  hideEdit: true,
  hideDetail: true,
  searchable: true
},
{
  field: 'reqName',
  title: '需求名称',
  type: 'text',
  searchable: true

},
{
  field: 'planId',
  title: '招聘规划',
  type: 'selectbyurl',
  url: '/dropdownlists/selectPlanList',
  init: (form, item) => {
    if (form.orgId) {
      const params = {
        orgId: form.orgId
      }
      const options = []
      getPositionApi(params).then(response => {
        if (response.success) {
          let data = []
          if (response.data) {
            data = response.data
          }
          data.forEach(v => {
            const a = {
              name: v.postName,
              value: v.postId
            }
            options.push(a)
          })
          form.startingSalary = response.data.salaryLow
          form.topSalary = response.data.salaryHigh
          detailSetting.forEach(v => {
            if (v.field === 'position') {
              v.options = []
              v.options = options
            }
          })
          if (form.position && form.orgId) {
            const params = {
              orgId: form.orgId,
              postId: form.position
            }
            findSalaryTwo(params).then(response => {
              if (response.success) {
                form.startingSalary = response.data.salaryLow
                form.topSalary = response.data.salaryHigh
              }
            })
          }
        }
      })
    }
  },
  itemChange: (form, item) => {
    if (form.planId) {
      getOrgdetail(form.planId).then(response => {
        if (response.success) {
          if (response.data) {
            form.orgId = response.data.orgId
            const params = {
              orgId: form.orgId
            }
            const options = []
            getPositionApi(params).then(response => {
              if (response.success) {
                let data = []
                if (response.data) {
                  data = response.data
                }
                data.forEach(v => {
                  const a = {
                    name: v.postName,
                    value: v.postId
                  }
                  options.push(a)
                })
                // form.position = ''
                form.startingSalary = ''
                form.topSalary = ''
                detailSetting.forEach(v => {
                  if (v.field === 'position') {
                    v.options = []
                    // form.position = ''
                    v.options = options
                  }
                })
              }
            })
          }
        }
      })
    }
  }
},
{
  field: 'position',
  title: '岗位名称',
  type: 'selected',
  options: [],
  itemChange: (form, item) => {
    if (form.position && form.orgId) {
      const params = {
        orgId: form.orgId,
        postId: form.position
      }
      findSalaryTwo(params).then(response => {
        if (response.success) {
          form.startingSalary = response.data.salaryLow
          form.topSalary = response.data.salaryHigh
        }
      })
    }
  }
},
{
  field: 'orgId',
  title: '所属部门',
  info: '所属部门默认为招聘规划所添加部门, 请先选择招聘规划',
  type: 'org',
  changeOnSelect: true,
  searchable: true,
  disableEdit: true
},
{
  field: 'startingSalary',
  info: '起始薪资为定岗定薪所设定薪资，不可修改',
  title: '起始薪资',
  type: 'text',
  disableEdit: true
},
{
  field: 'topSalary',
  title: '最高薪资',
  info: '最高薪资为定岗定薪所设定薪资，不可修改',
  type: 'text',
  disableEdit: true
},

{
  field: 'recruitsNumbers',
  title: '招聘人数',
  type: 'text'
},
{
  field: 'responsiblePerson',
  title: '负责人',
  type: 'user-tree',
  isHiden: true
},

{
  field: 'startDate',
  title: '启动日期',
  type: 'date'
},
{
  field: 'endDate',
  title: '结束日期',
  type: 'date'
},
{
  field: 'workNature',
  title: '工作性质',
  type: 'selected',
  isParams: true, // 默认为false，当isParams 为true 时，下拉数据为参数类型，
  paramsId: 'NATUREWORK'
},
{
  field: 'workExperienceRequire',
  title: '工作经验',
  type: 'selected',
  isParams: true, // 默认为false，当isParams 为true 时，下拉数据为参数类型，
  paramsId: 'EXPERIENCEWORK'
},
{
  field: 'educationRequire',
  title: '学历要求',
  type: 'selected',
  isParams: true, // 默认为false，当isParams 为true 时，下拉数据为参数类型，
  paramsId: 'EDUCATION'
}, {
  field: 'postRequire',
  title: '岗位要求',
  type: 'text'
},
{
  field: 'workRequire',
  title: '任职要求',
  type: 'text'
},
{
  field: 'recruitsReason',
  title: '招聘原因',
  type: 'text'
},
{
  field: 'workCity',
  title: '工作城市',
  type: 'text'
}
]
/**
 * 停止招聘set
 */
export const stopSetting = [{
  field: 'stopReason',
  title: '停止招聘原因',
  type: 'text'
}]

export const searchSetting = [
  // {
  //   field: 'reqId',
  //   title: '需求编号',
  //   type: 'text',
  //   searchable: true
  // },
  {
    field: 'reqName',
    title: '需求名称',
    type: 'text',
    searchable: true
  },
  {
    field: 'orgId',
    title: '部门',
    type: 'org',
    searchable: true
  }
]
